package com.firemoss.magicbus.messaging
{
	import mx.messaging.messages.AsyncMessage;
	import mx.messaging.messages.IMessage;

	public class DefaultProducerMessageConverter extends AbstractDefaultMessageConverter implements IProducerMessageConverter
	{

		public function DefaultProducerMessageConverter( messageAgentMediator : IMessageAgentMediator )
		{
			super( messageAgentMediator )
		}

		public function convert(mediator:IProducerMediator, event:Object):IMessage
		{
			
			var message : AsyncMessage = new AsyncMessage()
			
			message.body = []

			if ( mediator.bodyProperties )
			{
				for ( var item : String in mediator.bodyProperties )
				{
					message.body[ item ] = event[ item ]
				} 
			}
			else if ( mediator.bodyProperty )
			{
				message.body = event[ mediator.bodyProperty ]
			}
			
			return message

		}
		
	}
}